/*
 * menuSemanal.java
 *
 * Created on 2 de diciembre de 2008, 11:13
 */

package clases;

import java.util.Vector;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author  USUARIO
 */
public class menuSemanal extends javax.swing.JFrame {
    private Vector<Receta> menus = new Vector<Receta>(0,1);
    /** Creates new form menuSemanal */
    public menuSemanal() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        menu = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("Menu semanal");

        menu.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null}
            },
            new String [] {
                "Lunes", "Martes", "Miercoles", "Jueves", "Viernes", "Sabado", "Domingon"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        menu.setSelectionBackground(new java.awt.Color(17, 98, 227));
        menu.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                menuMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(menu);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 605, Short.MAX_VALUE)
                    .addComponent(jLabel1))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(31, 31, 31)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
public Receta buscarReceta(String n){
    Receta r = null;
    int i = 0;
    while(i < menus.size()){
        if(menus.get(i).getNombre() == n)return menus.get(i);
        i++;
    }
    return r;
}
private void menuMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_menuMouseClicked
// TODO add your handling code here:
    int i = menu.getSelectedRow();
    int j = menu.getSelectedColumn();
    String rec = (String)menu.getValueAt(i,j);
    Receta r = buscarReceta(rec);
    if(r != null){
        Vector<Receta> vector = new Vector<Receta>(0,1);
        vector.add(r);
        mostrarReceta m = new mostrarReceta();
        m.setRecetas(vector);
        m.setVisible(true);
    }
}//GEN-LAST:event_menuMouseClicked

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new menuSemanal().setVisible(true);
            }
        });
    }
public void setDatos(Vector<Receta> r){
    menus = r;
    DefaultTableModel modelo = new DefaultTableModel();
    String []s1={"LCo","MCo","XCo","JCo","VCo","SCo","DCo"};
    String []s2={"LCe","MCe","XCe","JCe","VCe","SCe","DCe"};
    
    modelo.addColumn("Lunes");
    modelo.addColumn("Martes");
    modelo.addColumn("Miercoles");
    modelo.addColumn("Jueves");
    modelo.addColumn("Viernes");
    modelo.addColumn("Sabado");
    modelo.addColumn("Domingo");
    int i=0;
    int j=0;
    while(i < r.size()){
        s1[j] = r.elementAt(i).getNombre();
        s2[j] = r.elementAt(i+1).getNombre();
        i = i+2;j++;
    }
    modelo.insertRow(0, s1);
    modelo.insertRow(1, s2);
    menu.setModel(modelo);
}
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable menu;
    // End of variables declaration//GEN-END:variables

}
